//
//  AppDelegate.m
//  FVQuickMessage
//
//  Created by dllo on 16/8/9.
//  Copyright © 2016年 zty. All rights reserved.
//

#import "AppDelegate.h"
#import "MyViewController.h"
#import "AddressViewController.h"
#import "FoundViewController.h"
#import "MQLogonVCOfMinDy.h"
#import "MessageSendViewController.h"

#import <EaseMob.h>


@interface AppDelegate ()<EMChatManagerDelegate>

@property (nonatomic, weak) MQLogonVCOfMinDy *loginVC;


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
    MQLogonVCOfMinDy *loginVC = [[MQLogonVCOfMinDy alloc]init];
    
    UINavigationController *loginNav = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.window.rootViewController = loginNav;
    
    //kSDKConfigEnableConsoleLogger 关闭控制台的打印
    [[EaseMob sharedInstance]registerSDKWithAppKey:@"373950462#fvquickmessage" apnsCertName:@"" otherConfig:@{kSDKConfigEnableConsoleLogger:@NO}];
   
    //调用环信的程序加载完毕的方法，才能添加代理
    
    [[EaseMob sharedInstance]application:application didFinishLaunchingWithOptions:launchOptions];
    
    //添加代理
    [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil];
    
    //自动登录
    if ([[EaseMob sharedInstance].chatManager isAutoLoginEnabled]) {
        
        [self loginSuccess];
        
    }
    
    return YES;
}


//登录成功
-(void)loginSuccess{
    
    

    
    //通讯录
    MessageSendViewController *addressVC = [[MessageSendViewController alloc]init];
    UINavigationController *naviAddress = [[UINavigationController alloc]initWithRootViewController:addressVC];
    UIImage *imageAN =  [UIImage imageNamed:@"通讯录"];
    
    naviAddress.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"通讯录" image:imageAN tag:101];
    //发现
    FoundViewController *foundVC = [[FoundViewController alloc]init];
    UINavigationController *naviFound = [[UINavigationController alloc]initWithRootViewController:foundVC];
    UIImage *imageFN = [UIImage imageNamed:@"发现"];
    
    naviFound.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"发现" image:imageFN tag:102];
    //我的
    MyViewController *myVC= [[MyViewController alloc]init];
    UINavigationController *naviMy = [[UINavigationController alloc]initWithRootViewController:myVC];
    UIImage *imageMN = [UIImage imageNamed:@"我的"];
    
    naviMy.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:imageMN tag:103];
    
    
    UITabBarController *controller = [[UITabBarController alloc]init];
    
    
    controller.viewControllers = @[ naviAddress,naviFound , naviMy];
    self.window.rootViewController = controller;
    
    
    
    
    
    
}
//退出登录
-(void)logOutSuccess{
    
        MQLogonVCOfMinDy *loginVC = [[MQLogonVCOfMinDy alloc]init];
    
    UINavigationController *loginNav = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.window.rootViewController = loginNav;
    
}

#pragma make - EMChatManagerDelegate 代理方法

-(void)willAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error{
    
    NSLog(@"即将自动登录");
    
}
-(void)didAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error{
    
    NSLog(@"自动登录成功");
    
}


//APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
    
    [[EaseMob sharedInstance] applicationDidEnterBackground:application];
    
    
}

//APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application {
    
    [[EaseMob sharedInstance] applicationWillEnterForeground:application];

    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
   
    
    [[EaseMob sharedInstance]applicationWillTerminate:application];

    
}

@end
